package com.shoulder.boot.acl.controller;

import com.shoulder.boot.acl.dto.MenuAddDTO;
import com.shoulder.boot.acl.dto.MenuModDTO;
import com.shoulder.boot.acl.entity.Menu;
import com.shoulder.boot.acl.service.MenuService;
import com.shoulder.boot.acl.vo.LeftMenuVo;
import com.shoulder.core.api.ApiResult;
import com.shoulder.log.annotation.LogAnnotation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单信息管理
 */
@RestController
@RequestMapping("/admin/api/v1/acl/menu")
@AllArgsConstructor
public class MenuController {
    private final MenuService menuService;

    /**
     * 获取业务及菜单
     */
    @GetMapping("/exclude/button")
    @LogAnnotation(type = "获取业务及菜单", record = false)
    public ApiResult<List<Menu>> excludeButton() {
        return ApiResult.ok(menuService.excludeButton());
    }

    /**
     * 根据id删除菜单
     * @param id 菜单id
     * @return ApiResult<Object>
     */
    @DeleteMapping("/{id}")
    @LogAnnotation(type = "删除菜单")
    public ApiResult<Object> del(@PathVariable String id) {
        menuService.menuDel(id);
        return ApiResult.ok();
    }

    /**
     * 添加菜单
     */
    @PostMapping
    @LogAnnotation(type = "添加菜单")
    public ApiResult<Object> add(@RequestBody @Validated MenuAddDTO addDTO) {
        menuService.menuAdd(addDTO);
        return ApiResult.ok();
    }

    /**
     * 修改菜单
     */
    @PutMapping
    @LogAnnotation(type = "修改菜单")
    public ApiResult<Object> mod(@RequestBody @Validated MenuModDTO modDTO) {
        menuService.menuMod(modDTO);
        return ApiResult.ok();
    }

    /**
     * 获取菜单树
     */
    @GetMapping("/tree")
    public ApiResult<List<Menu>> tree() {
        List<Menu> menus = menuService.tree();
        return ApiResult.ok(menus);
    }

    /**
     * 获取当前登录人的菜单信息
     */
    @GetMapping("/me")
    public ApiResult<List<LeftMenuVo>> menuMe() {
        List<LeftMenuVo> menus = menuService.me();
        return ApiResult.ok(menus);
    }
}